package top.yangbuyi.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.yangbuyi.acpect.annotaction.Log;
import top.yangbuyi.acpect.enums.BusinessType;
import top.yangbuyi.dto.RegisteredItemDto;
import top.yangbuyi.service.impl.RegisteredItemService;
import top.yangbuyi.utils.ShiroSecurityUtils;
import top.yangbuyi.vo.AjaxResult;
import top.yangbuyi.vo.DataGridView;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;


/**
 * @description: 杨不易网站:www.yangbuyi.top
 * @program: yangbuyiopenHis2020
 * @ClassName: RegisteredItemController
 * @create: 2020-09-11 23:02
 * @author: yangbuyi
 * @since： JDK1.8
 * @RegisteredItemController: 挂号费用设置$
 **/

@RestController
@RequestMapping("system/registeredItem")
public class RegisteredItemController {

	  @Autowired
	  private RegisteredItemService registeredItemService;

	  /**
	   * 分页查询
	   */
	  @GetMapping("listRegisteredItemForPage")
	  public AjaxResult listRegisteredItemForPage(RegisteredItemDto registeredItemDto) {
			DataGridView gridView = this.registeredItemService.listRegisteredItemPage(registeredItemDto);
			return AjaxResult.success("查询成功", gridView.getData(), gridView.getTotal());
	  }

	  /**
	   * 查询全部可用的挂号
	   *
	   * @param registeredItemDto
	   * @return
	   */
	  @GetMapping("selectAllRegisteredItem")
	  public AjaxResult selectAllRegisteredItem() {
			return AjaxResult.success(this.registeredItemService.selectAllRegisteredItem());
	  }

	  /**
	   * 添加
	   */
	  @PostMapping("addRegisteredItem")
	  @Log(title = "添加挂号", businessType = BusinessType.INSERT)
	  public AjaxResult addRegisteredItem(@Validated RegisteredItemDto registeredItemDto) {
			registeredItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
			return AjaxResult.toAjax(this.registeredItemService.addRegisteredItem(registeredItemDto));
	  }

	  /**
	   * 修改
	   */
	  @PutMapping("updateRegisteredItem")
	  @Log(title = "修改挂号", businessType = BusinessType.UPDATE)
	  public AjaxResult updateRegisteredItem(@Validated RegisteredItemDto registeredItemDto) {
			registeredItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
			return AjaxResult.toAjax(this.registeredItemService.updateRegisteredItem(registeredItemDto));
	  }


	  /**
	   * 根据ID查询一个挂号信息
	   */
	  @GetMapping("getRegisteredItemById/{registeredItemId}")
	  public AjaxResult getRegisteredItemById(@PathVariable @Validated @NotNull(message = "挂号ID不能为空") Long registeredItemId) {
			return AjaxResult.success(this.registeredItemService.getOne(registeredItemId));
	  }

	  /**
	   * 删除
	   */
	  @DeleteMapping("deleteRegisteredItemByIds/{registeredItemIds}")
	  @Log(title = "删除挂号", businessType = BusinessType.DELETE)
	  public AjaxResult deleteRegisteredItemByIds(@PathVariable @Validated @NotEmpty(message = "要删除的ID不能为空") Long[] registeredItemIds) {
			return AjaxResult.toAjax(this.registeredItemService.deleteRegisteredItemByIds(registeredItemIds));
	  }


}
